package com.kiven.callback;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * JAVA的CallBack通过接口来实现
 * 1.class A,class B  
 * 2.class A实现接口operate  
 * 3.class B拥有一个参数为operate接口类型的函数test(operate o)  
 * 4.class A运行时调用class B中test函数,以自身传入参数  
 * 5.class B已取得A，就可以随时回调A所实现的operate接口中的方法
 * @author KivenLi
 *
 */

interface BoomWTC {
	//获取本拉登决定
	public boolean benLaDengDecide();
	//执行轰炸世贸中心
	public void boom();
}

class At911 implements BoomWTC {
	private boolean decide;
	private TerroristAttack ta;
	
	public At911() {
		Date date = new Date();
		SimpleDateFormat sf = new SimpleDateFormat("yyyy/MM/dd");
		this.decide = sf.format(date).equals("2010/11/03");
		this.ta = new TerroristAttack();
	}
	
	public boolean benLaDengDecide() {
		return decide;
	}
	
	@Override
	public void boom() {
		ta.attack(new At911());
	}
}

public class TerroristAttack {
	public TerroristAttack() {}
	
	public void attack(BoomWTC bmw) {
		if(bmw.benLaDengDecide()) {
			System.out.println("WTC we attack you now.....hahahaha");
		}
	}
	
	public static void main(String[] args) {
		new At911().boom();
	}
}
